package com.guanzi.activiti.utils;

public class R<T>{

    private Integer code;
    private String message;
    private T data;

    public Integer getCode(){return code;}
    public void   setCode(){this.code = code;}
    public String getMessage(){return message;}
    public void   setMsg(){this.message = message;}
    public Object getData(){return data;}
    public void   setData(){this.data= data;}
    public R() {
    }

    public R(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public R(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 默认的成功
     * @return
     */
    public static R success(){
        return new R (200,"操作成功");
    }

    /**
     * 默认的失败
     * @return
     */
    public static R error(){
        return new R (500,"操作失败");
    }

    /**
     * 默认的失败
     * @return
     */
    public static R error(String msg){
        return new R (500,msg);
    }

    /**
     * 默认的失败
     * @return
     */
    public static R error(Integer code,String msg){
        return new R (code,msg);
    }

    /**
     * 成功 + 返回的成功信息
     * @param data
     * @return
     */
    public static <T> R<T> success(T data){
        return new R<T> (200,"操作成功",data);
    }

    /**
     * 自定义code，成功 + 返回的成功信息
     * @param code
     * @param data
     * @return
     */
    public static <T> R<T> success(Integer code, T data){
        return new R<T> (code,"操作成功",data);
    }

    /**
     * 自定义code，成功 + 返回的成功信息
     * @param code
     * @param msg
     * @return
     */
    public static <T> R<T> success(Integer code, String msg){
        return new R<T> (code,msg);
    }

    /**
     * 成功 + 返回的成功信息
     * @param data
     * @return
     */
    public static <T> R<T> success(T data,String msg){
        return new R<T> (200,msg,data);
    }

}
